/*******************************************************************************
 * Copyright (c) 2005, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/**
 * 
 */
package us.gaaoc.framework.dao;

import java.util.List;

import org.hibernate.Query;

import us.gaaoc.framework.model.CaseRecord;
import us.gaaoc.framework.model.CourtSeal;

/**
 * @author Sukahda Tapshalkar
 * Sep 22, 2006
 *
 */
public class CourtSealDAOHibernate extends
GenericHibernateDAO<CourtSeal, String, CourtSealDAO> implements
CourtSealDAO  {
	
	protected CourtSealDAOHibernate() {
		
	}

	public CourtSeal findCourtSealByDocumentID(String documentID) {
		Query q = this.getSession().createQuery("from CourtSeal cs where cs.document.uuid = ?");
		q.setString(0, documentID);
        return (CourtSeal)q.uniqueResult();
	}

	public int countDocumentAssociations(String documentUuid) {
		
		Query q = this.getSession().createQuery("select count(*) from CourtSeal" +
				" cs where cs.document.uuid = ?");
		q.setString(0, documentUuid);
		
		return Integer.parseInt(((Long)q.uniqueResult()).toString());
	}
	
	/*
	 * (non-Javadoc)
	 * @see us.gaaoc.framework.dao.CourtSealDAO#getDuplicateCourtSealList(java.lang.String)
	 */
	public List<CourtSeal> getDuplicateCourtSealList(String documentUuid) {
		
		Query q = this.getSession().createQuery("from CourtSeal cs where " +
				"cs.document.uuid = ?");
		q.setString(0, documentUuid);
		
		return q.list();
	}
	
	/*
	 * (non-Javadoc)
	 * @see us.gaaoc.framework.dao.CourtSealDAO#findCourtSealByID(int)
	 */
	public CourtSeal findCourtSealByID(int row) {
		
		Query q = this.getSession().createQuery("from CourtSeal cs")
			.setFirstResult(row).setMaxResults(1);
		
		return (CourtSeal)q.uniqueResult();
	}
	
	
}
